package br.com.lh.urabuilder.business
{
	import br.com.lh.urabuilder.view.ActionComponent;
	import br.com.lh.urabuilder.view.arrow.ArrowContainer;
	
	import mx.collections.ArrayCollection;
	
	public class ZoomManager
	{
		public var currentScale:Number = 1;
		
		private var viewManager:ViewManager;
		
		public const scaleDelta:Number =1.2;

		public function ZoomManager(viewManager:ViewManager){
			this.viewManager = viewManager;
		}
		
		
		public function zoom(zoomIn:Boolean =true):Number{
			var components:ArrayCollection = viewManager.getComponents();
			var oldScale:Number = currentScale;
			var zoomValue:Number = zoomIn ? 1/scaleDelta : scaleDelta;
			currentScale = oldScale * zoomValue; 
			for each (var element:ActionComponent in components){
				doZoom(element);
			}
			return oldScale;
		  }
		
		
		private function doZoom(element:ActionComponent):void{
			element.scaleX = currentScale;
			element.scaleY = currentScale;
			for each(var arrowContainer:ArrowContainer in element.children()){
				arrowContainer.scaleX = currentScale;
				arrowContainer.scaleY = currentScale;
			}
			
		}
		

	}
}